<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="content">
            <h:form rendered="#{loginBacking.listSystemUser}">
                <p:panel header="View All Employees">
                    <p:dataTable value="#{systemUserEntityController.items}" 
                                 var="item"
                                 paginator="true" rows="30"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="30,50,100">
                        <p:column filterBy="#{item.department.name}" sortBy="#{item.department.name}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListSystemUserEntityTitle_department}"/>
                            </f:facet>
                            <h:outputText value="#{item.department.name}"/>
                        </p:column>
                        <p:column filterBy="#{item.id}" sortBy="#{item.id}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListSystemUserEntityTitle_id}"/>
                            </f:facet>
                            <h:outputText value="#{item.id}"/>
                        </p:column>
                        <p:column filterBy="#{item.name}" sortBy="#{item.name}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListSystemUserEntityTitle_name}"/>
                            </f:facet>
                            <h:outputText value="#{item.name}"/>
                        </p:column>
                        <p:column filterBy="#{item.firstName}" sortBy="#{item.firstName}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListSystemUserEntityTitle_firstName}"/>
                            </f:facet>
                            <h:outputText value="#{item.firstName}"/>
                        </p:column>
                        <p:column filterBy="#{item.lastName}" sortBy="#{item.lastName}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListSystemUserEntityTitle_lastName}"/>
                            </f:facet>
                            <h:outputText value="#{item.lastName}"/>
                        </p:column>                   
                        <p:column filterBy="#{item.contact.email}" sortBy="#{item.contact.email}">
                            <f:facet name="header">
                                <h:outputText value="Email"/>
                            </f:facet>
                            <h:outputText value="#{item.contact.email}"/>
                        </p:column>      
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="View"/>
                            </f:facet>
                            <p:commandButton image="ui-icon ui-icon-search" ajax="false" action="#{systemUserEntityController.prepareView}">
                                <f:setPropertyActionListener value="#{item}"  
                                                             target="#{systemUserEntityController.current}" /> 
                            </p:commandButton>
                        </p:column>

                        <p:column>
                            <p:menuButton value="Options">  
                                <p:menuitem value=" Edit" ajax="false" icon="ui-icon ui-icon-disk" 
                                            action="#{systemUserEntityController.prepareEdit}" rendered="#{loginBacking.editSystemUser}">
                                    <f:setPropertyActionListener value="#{item}"  
                                                                 target="#{systemUserEntityController.current}" />
                                </p:menuitem>
                                <p:menuitem value=" Deactivate" ajax="false" rendered="#{(item.archived==false) and (loginBacking.editSystemUser)}" icon="ui-icon ui-icon-close"
                                            action="#{systemUserEntityController.destroy}">
                                    <f:setPropertyActionListener value="#{item}"  
                                                                 target="#{systemUserEntityController.current}" />
                                </p:menuitem> 
                                <p:menuitem value=" Activate" ajax="false" rendered="#{(item.archived==true) and (loginBacking.editSystemUser)}" icon="ui-icon ui-icon-close"
                                            action="#{systemUserEntityController.activate}">
                                    <f:setPropertyActionListener value="#{item}"  
                                                                 target="#{systemUserEntityController.current}" />
                                </p:menuitem> 
                            </p:menuButton>
                        </p:column>

                    </p:dataTable>
                </p:panel>
                <br />
                <h:commandButton action="#{systemUserEntityController.prepareCreate}" value="New System User" rendered="#{loginBacking.editSystemUser}"/>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
